﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace OpenCompiler.Scanning.Tests.Specs_for_scanner
{
	[TestClass]
	public class When_scanning_for_keywords
	{
		private static List<Token> Tokenize(string input)
		{
			var scanner = new Scanner(Constants.FakeFileName);
			return scanner.Tokenize(input);
		}

		[TestMethod]
		public void Using_statements_are_tokenized()
		{
			var sourceCode = "using System;\nusing System.Linq;";
			var tokens = Tokenize(sourceCode);
			Assert.AreEqual(8, tokens.Count); // Including EOF
			Assert.AreEqual(Keyword.USING, (Keyword)tokens[0].ActualToken);
			Assert.AreEqual("System", (string)tokens[1].ActualToken);
			Assert.AreEqual(Keyword.USING, (Keyword)tokens[4].ActualToken);
			Assert.AreEqual("System.Linq", (string)tokens[5].ActualToken);
		}

		[TestMethod]
		public void Brackets_are_tokenized()
		{
			var sourceCode = "{}";
			var tokens = Tokenize(sourceCode);
			Assert.AreEqual(3, tokens.Count);
			Assert.AreEqual(Formatting.ScopeStart, (Formatting)tokens[0].ActualToken);
			Assert.AreEqual(Formatting.ScopeEnd, (Formatting)tokens[1].ActualToken);
		}

		[TestMethod]
		public void Public_classes_are_tokenizer()
		{
			var sourceCode = "public class MyClass {}";
			var tokens = Tokenize(sourceCode);
			Assert.AreEqual(6,tokens.Count);
			Assert.AreEqual(Keyword.PUBLIC,(Keyword)tokens[0].ActualToken);
			Assert.AreEqual(Keyword.CLASS, (Keyword)tokens[1].ActualToken);
			Assert.AreEqual("MyClass", (string)tokens[2].ActualToken);
		}

	}
}